package com.example.springboot.search.service.impl;

import com.example.springboot.search.constant.PageConstant;
import com.example.springboot.search.entity.dto.ErrorListEnum;
import com.example.springboot.search.entity.dto.LogSearchResult;
import com.example.springboot.search.entity.dto.QueryDataDto;
import com.example.springboot.search.entity.dto.QueryDataVo;
import com.example.springboot.search.service.BaseService;
import com.example.springboot.search.util.C3P0Util;
import com.example.springboot.search.util.ResourceType;
import com.example.springboot.search.util.ThreadUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Service;

import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class BaseServiceImpl implements BaseService {
	private static Log log = LogFactory.getLog(BaseServiceImpl.class);

	/**
	 * 根据id查询单条数据
	 * 
	 * @param queryDataDto
	 * @return
	 * @throws Exception
	 */
	@Override
	public QueryDataVo<Map<String, Object>> queryById(QueryDataDto queryDataDto) throws Exception {

		long startTime = System.currentTimeMillis();
		QueryDataVo<Map<String, Object>> dataVo = new QueryDataVo<Map<String, Object>>();
		Long id = queryDataDto.getId();
		String tableName2 = queryDataDto.getTableName();
		Integer resourceType = queryDataDto.getResourceType();
		if ((id == null || id <= 0) //
				|| (resourceType == null || resourceType <= 0) //
				|| StringUtils.isEmpty(tableName2)) {//
			dataVo.setStatus(ErrorListEnum.E30001.getKey());
			dataVo.setMsg(ErrorListEnum.E30001.getValue());
			return dataVo;
		}

		try {
			// 拼接sql条件
			String sql = "select  * from " + tableName2 + " where id=" + id;
			// 查询数据
			Map<String, Object> map = C3P0Util.getMap(sql);
			// 拼接字典信息
			// DictionaryParse.decode(map);
			dataVo.setRows(map);
			dataVo.setTotal(1L);
		} catch (Exception e) {
			log.error("日志查询异常:", e);
			dataVo.setStatus(ErrorListEnum.E30003.getKey());
			dataVo.setMsg(ErrorListEnum.E30003.getValue());
		}
		Long time = (System.currentTimeMillis() - startTime);
		dataVo.setStatus(ErrorListEnum.E200.getKey());
		dataVo.setMsg(ErrorListEnum.E200.getValue());
		dataVo.setTime(time);

		log.info(">>>>>>>>>查询日志总耗时： " + time);
		return dataVo;
	}

	/**
	 * 分页查询特征数据
	 * 
	 * @param queryDataDto
	 * @return
	 * @throws Exception
	 */
	public QueryDataVo<List<Map<String, Object>>> queryBaseByPage(QueryDataDto queryDataDto) throws Exception {
		queryDataDto.setByPage(true);
		// queryDataDto.setType(false);
		return getBaseDataResult(queryDataDto);
	}

	/**
	 * 查询特征数据
	 * 
	 * @param queryDataDto
	 * @return
	 * @throws Exception
	 */
	public QueryDataVo<List<Map<String, Object>>> queryBaseList(QueryDataDto queryDataDto) throws Exception {
		return getBaseDataResult(queryDataDto);
	}

	/**
	 * 查询所有，不分页
	 * 
	 * @param queryDataDto
	 * @return
	 * @throws Exception
	 */
	public QueryDataVo<List<Map<String, Object>>> queryLogList(QueryDataDto queryDataDto) throws Exception {
		queryDataDto.setType(true);
		return query(queryDataDto);
	}

	/**
	 * 分页查询所有日志数据
	 * 
	 * @param queryDataDto
	 * @return
	 * @throws Exception
	 */
	public QueryDataVo<List<Map<String, Object>>> queryLogByPage(QueryDataDto queryDataDto) throws Exception {
		queryDataDto.setByPage(true);
		queryDataDto.setType(true);
		return query(queryDataDto);
	}

	/**
	 * 查询总数
	 * 
	 * @param queryDataDto
	 * @return
	 * @throws Exception
	 */
	public QueryDataVo<List<Map<String, Object>>> queryTotal(QueryDataDto queryDataDto) throws Exception {

		QueryDataVo<List<Map<String, Object>>> dataVo = new QueryDataVo<List<Map<String, Object>>>();
		Integer resourceType = queryDataDto.getResourceType();
		if (resourceType == null || resourceType <= 0) {//
			dataVo.setStatus(ErrorListEnum.E30001.getKey());
			dataVo.setMsg(ErrorListEnum.E30001.getValue());
			return dataVo;
		}

		Long total = 0L;
		boolean type = queryDataDto.isType();
		if (type) {
			// 根据算法分页查询表,最多支持一次20000条
			List<String> condList = getSearchCondition(queryDataDto);
			total = ThreadUtils.execute(condList);
		} else {
			// 基础书
			String sql = getSearchSQL(queryDataDto, null, null);
			if (StringUtils.isEmpty(sql)) {
				dataVo.setStatus(ErrorListEnum.E30001.getKey());
				dataVo.setMsg(ErrorListEnum.E30001.getValue());
				return dataVo;
			}
			String countSql = " select count(id) from (" + sql + ") as tmp ORDER BY id desc ";
			total = C3P0Util.getCount(countSql);
		}
		dataVo.setTotal(total);
		return dataVo;
	}

	/**
	 * 为条件拼接上分库分表的库名后缀和表名后缀
	 */
	private QueryDataVo<List<Map<String, Object>>> getBaseDataResult(QueryDataDto queryDataDto) {

		long startTime = System.currentTimeMillis();
		QueryDataVo<List<Map<String, Object>>> dataVo = new QueryDataVo<List<Map<String, Object>>>();

		Integer resourceType = queryDataDto.getResourceType();
		Integer page = queryDataDto.getPage();
		Integer rows = queryDataDto.getRows();

		if (resourceType == null || resourceType <= 0) {//
			dataVo.setStatus(ErrorListEnum.E30001.getKey());
			dataVo.setMsg(ErrorListEnum.E30001.getValue());
			return dataVo;
		}

		try {
			String sql = getSearchSQL(queryDataDto, null, null);
			if (StringUtils.isEmpty(sql)) {
				dataVo.setStatus(ErrorListEnum.E30001.getKey());
				dataVo.setMsg(ErrorListEnum.E30001.getValue());
				return dataVo;
			}
			// 查询数据
			LogSearchResult result = new LogSearchResult();
			Map<String, Object> map = getTablePageIndex(page, rows, result.getCurrCount(), result.getTotal());
			result = this.getDataList(result, sql, map, queryDataDto);
			// 拼接字典信息
			List<Map<String, Object>> list = result.getRows();
			// 拼接字典信息
			// DictionaryParse.decode(list);
			dataVo.setRows(list);
			dataVo.setTotal(result.getTotal());
		} catch (Exception e) {
			log.error("日志查询异常:", e);
			dataVo.setStatus(ErrorListEnum.E30003.getKey());
			dataVo.setMsg(ErrorListEnum.E30003.getValue());
			return dataVo;
		}

		Long time = (System.currentTimeMillis() - startTime);
		dataVo.setStatus(ErrorListEnum.E200.getKey());
		dataVo.setMsg(ErrorListEnum.E200.getValue());
		dataVo.setTime(time);

		log.info(">>>>>>>>>查询日志总耗时： " + time);
		return dataVo;
	}

	/**
	 * 
	 * @param queryDataDto
	 *            :分页查询查询条件
	 *            :根据ResourceType的类型查询（实名/终端mac/热点mac/虚拟省份/车牌/imsi/imei/人脸等）
	 * @return
	 * @throws Exception
	 */
	public QueryDataVo<List<Map<String, Object>>> query(QueryDataDto queryDataDto) throws Exception {

		long startTime = System.currentTimeMillis();
		QueryDataVo<List<Map<String, Object>>> dataVo = new QueryDataVo<List<Map<String, Object>>>();
		String beginTime = queryDataDto.getBeginTime();
		String endTime = queryDataDto.getEndTime();
		Integer resourceType = queryDataDto.getResourceType();

		// 校验数据
		if (StringUtils.isEmpty(beginTime) //
				|| StringUtils.isEmpty(endTime)//
				|| (resourceType == null || resourceType <= 0)) {//

			dataVo.setStatus(ErrorListEnum.E30001.getKey());
			dataVo.setMsg(ErrorListEnum.E30001.getValue());
			return dataVo;
		}

		try {
			// 根据算法分页查询表,最多支持一次20000条
			List<String> condList = getSearchCondition(queryDataDto);
			// 拼接字典信息
			dataVo = getLogDataResult(condList, queryDataDto);
			List<Map<String, Object>> list = dataVo.getRows();
			// 拼接字典信息
			// DictionaryParse.decode(list);
		} catch (Exception e) {
			log.error("日志查询异常:", e);
			dataVo.setStatus(ErrorListEnum.E30003.getKey());
			dataVo.setMsg(ErrorListEnum.E30003.getValue());
			return dataVo;
		}

		Long time = (System.currentTimeMillis() - startTime);
		dataVo.setStatus(ErrorListEnum.E200.getKey());
		dataVo.setMsg(ErrorListEnum.E200.getValue());
		dataVo.setTime(time);

		log.info(">>>>>>>>>查询日志总耗时： " + time);
		return dataVo;
	}

	/**
	 * 循环查询数据表,按照时间倒序查询,查询到指定的数量即可
	 * 
	 * @param condList
	 * @param queryDataDto
	 * @return
	 * @throws SQLException
	 */
	private QueryDataVo<List<Map<String, Object>>> getLogDataResult(List<String> condList, QueryDataDto queryDataDto) throws SQLException {

		QueryDataVo<List<Map<String, Object>>> chartVo = new QueryDataVo<List<Map<String, Object>>>();
		Integer rows = queryDataDto.getRows();
		Integer page = queryDataDto.getPage();

		long startTime = System.currentTimeMillis();
		if (condList != null && condList.size() > 0) {
			LogSearchResult result = new LogSearchResult();
			for (String condition : condList) {
				// 获取分页参数
				if (result.getCurrCount() >= queryDataDto.getRows())
					break;
				Map<String, Object> map = getTablePageIndex(page, rows, result.getCurrCount(), result.getTotal());
				result = getDataList(result, condition, map, queryDataDto);

			}
			chartVo.setRows(result.getRows());
			chartVo.setTotal(result.getTotal());
		}
		long endTime = System.currentTimeMillis();
		log.info("查询日志耗时： " + (endTime - startTime));
		return chartVo;
	}

	/**
	 * 查询分页数据
	 * 
	 * @param result
	 * @param sql
	 * @return
	 * @throws SQLException
	 */
	private LogSearchResult getDataList(LogSearchResult result, String sql, Map<String, Object> map, QueryDataDto queryDataDto) throws SQLException {
		long startTime = System.currentTimeMillis();
		try {
			// 查询数据
			String countSql = " select count(id) from (" + sql + ") as tmp ORDER BY id desc ";
			if (queryDataDto.isByPage()) {
				// 分页查询
				sql = getPageSQL(sql);
				sql += " order by Time desc limit " + map.get("start") + "," + map.get("end");
				// sql += " where tmp.rn>=" + map.get("start") + " AND tmp.rn<"
				// +
				// map.get("end");
			}
			// 查询数据
			Long total = C3P0Util.getCount(countSql);
			List<Map<String, Object>> list = C3P0Util.getMapList(sql);
			result.getRows().addAll(list);
			// result.setTotal(result.getTotal() + 10000L);
			result.setTotal(result.getTotal() + total);
			result.setCurrCount(result.getCurrCount() + total);
			// result.setCurrCount(result.getCurrCount() + 10000L);
		} catch (Exception e) {
			e.printStackTrace();
			log.error("查询数据异常：" + e);
		}
		log.info("mybatis查询日志耗时： " + (System.currentTimeMillis() - startTime));
		return result;
	}

	/**
	 * 获取分页参数
	 * 
	 * @param page
	 *            :开始页数
	 * @param rows
	 *            ：每页记录数
	 * @param currCount
	 *            ：当前查询数据库数据
	 * @param total
	 *            ：总数
	 * @return
	 */
	private Map<String, Object> getTablePageIndex(Integer page, Integer rows, Long currCount, Long total) {
		Map<String, Object> map = new HashMap<String, Object>();
		// 通过与上次获取数据的数值进行比较,获取需要拿出的数量
		Long size = rows - currCount;
		// 用总条数查询出起始的条数
		Long start = (page - 1) * size;
		// 如果结束数量大于0,并且总量大于0,说明还没有达到需要的数量
		if (total > 0 && size > 0) {
			// 计算出余数
			Long remainder = (Long) total % rows;
			// 判断是否能够整除从而获取组数
			Long group = remainder == 0 ? total / rows : total / rows + 1;
			// 如果上次拿出的大于零,说明上次数据不够,本次应该从第一页开始,如果小于零,则需要计算出起始页数
			// 起始页数计算方式:当前已经查询过的页数 * 每页条数 + 如果有余数的话要加上要拿出的数与余数的差
			Long count = size * ((page - 1) - group) + (remainder != 0 ? size - remainder : 0);
			start = (Long) (currCount > 0 ? 0 : count);
		}
		map.put("start", start);
		map.put("end", size);
		// map.put("end", String.valueOf(start + size));
		return map;
	}

	/**
	 * 根据条件生产查询表sql语句
	 * 
	 * @param queryDataDto
	 *            ：查询条件
	 * @param databaseName
	 *            :数据库名称
	 * @param tableName
	 *            ：表名称
	 * @return
	 */
	private String getSearchSQL(QueryDataDto queryDataDto, String databaseName, String tableName) {

		String beginTime = queryDataDto.getBeginTime();
		String endTime = queryDataDto.getEndTime();
		Integer resourceType = queryDataDto.getResourceType();
		Integer dataType = queryDataDto.getDataType();
		String text = queryDataDto.getText();
		String machineCode = queryDataDto.getMachineCode();
		// 是否分页(是-true;否-false)
		boolean byPage = queryDataDto.isByPage();
		// 查询Log-true/base类型
		boolean type = queryDataDto.isType();

		// 日志表名称
		databaseName = StringUtils.isEmpty(databaseName) ? "" : databaseName;
		tableName = StringUtils.isEmpty(tableName) ? "" : tableName;
		tableName = databaseName + "." + tableName;
		if (!type) {
			// base基础表
			tableName = getTableName(resourceType, dataType);
		}
		if (StringUtils.isEmpty(tableName)) {
			return null;
		}

		// 拼接sql语句
		StringBuilder sub = new StringBuilder();
		sub.append(" select A.*,'" + tableName + "' as tableName  from " + tableName + " as A where 1=1 ");
		if (StringUtils.isNotBlank(beginTime) && StringUtils.isNotBlank(endTime)) {
			sub.append(" AND A.Time  BETWEEN  '" + beginTime + "' ");
			sub.append(" AND  '" + endTime + "' ");
		}

		switch (resourceType) {
		case 1:
		case 31:
		case 40:
			// 真实身份
			if (dataType != null && dataType > 0) {
				sub.append(" AND A.RealType='" + dataType + "' ");
			}
			if (StringUtils.isNotBlank(text)) {
				sub.append(" AND A.RealCode like '" + text + "%' ");
			}
			break;
		case 2:
		case 32:
			// 终端amc
			if (StringUtils.isNotBlank(text)) {
				sub.append(" AND A.TerminalMac like '" + text + "%' ");
			}
			break;
		case 3:
		case 33:
			// 热点mac
			if (StringUtils.isNotBlank(text)) {
				sub.append(" AND ( A.RouteMac like '" + text + "%' ");
				sub.append(" OR A.SSID like '" + text + "%' ) ");
			}
			break;
		case 8:
		case 41:
			// 虚拟身份
			if (dataType != null && dataType > 0) {
				sub.append(" AND A.ProtoType='" + dataType + "' ");
			}
			if (StringUtils.isNotBlank(text)) {
				sub.append(" AND A.CyberCode like '" + text + "%' ");
			}
			break;
		case 9:
			// 其他
			if (dataType != null && (dataType == 11 || dataType == 49)) {
				if (StringUtils.isNotBlank(text)) {
					sub.append(" AND A.PlateNum like '" + text + "%' ");
				}
			} else if (dataType != null && (dataType == 12 || dataType == 50)) {
				if (StringUtils.isNotBlank(text)) {
					sub.append(" AND A.IMSI like '" + text + "%' ");
				}
			}
			break;
		case 11:
		case 49:
			// 车牌
			if (StringUtils.isNotBlank(text)) {
				sub.append(" AND A.PlateNum like '" + text + "%' ");
			}
			break;
		case 12:
		case 50:
			// IMSI
			if (StringUtils.isNotBlank(text)) {
				sub.append(" AND A.IMSI like '" + text + "%' ");
			}
			break;
		case 13:
		case 51:
			// IMEI
			if (StringUtils.isNotBlank(text)) {
				sub.append(" AND A.IMEI like '" + text + "%' ");
			}
			break;
		case 14:
		case 43:
			// 群组
			if (dataType != null && dataType > 0) {
				sub.append(" AND A.ProtoType='" + dataType + "' ");
			}
			if (StringUtils.isNotBlank(text)) {
				sub.append(" AND A.GroupAccount like '" + text + "%' ");
			}
			break;
		case 16:
		case 56:
			// 人脸
			if (StringUtils.isNotBlank(text)) {
				sub.append(" AND A.FaceClusterID like '" + text + "%' ");
			}
			break;
		default:
			break;
		}

		// 设备
		if (StringUtils.isNotBlank(machineCode)) {
			sub.append(" AND A.MachineCode='" + machineCode + "' ");
		}
		// geohash查询
		String startRowKey = queryDataDto.getStartRowKey();
		String endRowKey = queryDataDto.getEndRowKey();
		if (StringUtils.isNotBlank(startRowKey) && StringUtils.isNotBlank(endRowKey)) {
			sub.append(" AND A.LatLon  BETWEEN  '" + startRowKey + "' ");
			sub.append(" AND  '" + endRowKey + "' ");
		}
		sub.append(" ORDER BY id desc ");

		// 是否分页
		// if (byPage) {
		// String sql = getPageSQL(sub.toString());
		// return sql;
		// } else {
		// return sub.toString();
		// }
		return sub.toString();
	}

	/**
	 * 获取分页sql语句
	 * 
	 * @param sql
	 * @return
	 */
	private String getPageSQL(String sql) {
		// 拼接分页数据
		StringBuilder resbuf = new StringBuilder();
		if (StringUtils.isNotBlank(sql)) {
			resbuf.append(" select * from ( ");
			resbuf.append(sql);
			resbuf.append(" ) as temp ");
		}
		return resbuf.toString();
	}

	/**
	 * 获取基础表名称
	 * 
	 * @param resourceType
	 * @param dataType
	 * @return
	 */
	private String getTableName(Integer resourceType, Integer dataType) {
		switch (resourceType) {
		case 1:
			// 真实身份
		case 2:
			// 终端amc
		case 3:
			// 热点mac
		case 9:
			// 其他
			if (dataType != null && dataType == 11) {
				return PageConstant.DATABASE_NAME + "." + PageConstant.FPSOP_tb_Car;
			} else if (dataType != null && dataType == 12) {
				return PageConstant.DATABASE_NAME + "." + PageConstant.FPSOP_tb_IMSI;
			}
		case 8:
			// 虚拟身份
		case 11:
			// 车牌
		case 12:
		case 13:
			// IMEI
		case 14:
			// 群组
		case 16:
			// 人脸
			String tableName = String.valueOf(ResourceType.toEnum(resourceType));
			return PageConstant.DATABASE_NAME + "." + tableName;

		case 31:
		case 40:
		case 32:
		case 33:
		case 41:
		case 43:
		case 49:
		case 50:
		case 51:
		case 56:
			// 人脸
		case 118:
			// STG日志表
			tableName = String.valueOf(ResourceType.toEnum(resourceType));
			return tableName;
		default:
			break;
		}
		return null;
	}

	// /**
	// * 获取基础表名称
	// *
	// * @param resourceType
	// * @param dataType
	// * @return
	// */
	// private String getTableName(Integer resourceType, Integer dataType) {
	// switch (resourceType) {
	// case 1:
	// // 真实身份
	// return PageConstant.DATABASE_NAME + "." + PageConstant.FPSOP_tb_RealName;
	// case 2:
	// // 终端amc
	// return PageConstant.DATABASE_NAME + "." + PageConstant.FPSOP_tb_Terminal;
	// case 3:
	// // 热点mac
	// return PageConstant.DATABASE_NAME + "." + PageConstant.FPSOP_tb_Route;
	// case 9:
	// // 其他
	// if (dataType != null && dataType == 11) {
	// return PageConstant.DATABASE_NAME + "." + PageConstant.FPSOP_tb_Car;
	// } else if (dataType != null && dataType == 12) {
	// return PageConstant.DATABASE_NAME + "." + PageConstant.FPSOP_tb_IMSI;
	// }
	// case 8:
	// // 虚拟身份
	// return PageConstant.DATABASE_NAME + "." + PageConstant.FPSOP_tb_Cyber;
	// case 11:
	// // 车牌
	// return PageConstant.DATABASE_NAME + "." + PageConstant.FPSOP_tb_Car;
	// case 12:
	// return PageConstant.DATABASE_NAME + "." + PageConstant.FPSOP_tb_IMSI;
	// case 13:
	// // IMEI
	// return PageConstant.DATABASE_NAME + "." + PageConstant.FPSOP_tb_IMEI;
	// case 14:
	// // 群组
	// return PageConstant.DATABASE_NAME + "." + PageConstant.FPSOP_tb_Group;
	// case 16:
	// // 人脸
	// return PageConstant.DATABASE_NAME + "." + PageConstant.FPSOP_tb_Face;
	//
	// case 31:
	// case 40:
	// return PageConstant.FPSOP_Log_Customer;
	// case 32:
	// return PageConstant.FPSOP_Log_Terminal;
	// case 33:
	// return PageConstant.FPSOP_Log_Router;
	// case 41:
	// return PageConstant.FPSOP_Log_Cyber;
	// case 43:
	// return PageConstant.FPSOP_Log_GroupChat;
	// case 49:
	// return PageConstant.FPSOP_Log_Car;
	// case 50:
	// return PageConstant.FPSOP_Log_IMSI;
	// case 51:
	// return PageConstant.FPSOP_Log_IMEI;
	// case 56:
	// // 人脸
	// return PageConstant.FPSOP_Log_Face;
	// case 118:
	// // STG日志表
	// return PageConstant.FPSOP_Log_STG;
	// default:
	// break;
	// }
	// return null;
	// }

	/**
	 * TODO 获取某天的前后几天 返回类型 yyyyMMdd
	 * 
	 * @author zhanghan
	 * @date 2016-9-5
	 * @param date
	 * @param day
	 *            正数后几天,负数前几天
	 */
	public static Date getDateAlter(Date date, int day) {
		Calendar calendar = Calendar.getInstance();// 此时打印它获取的是系统当前时间
		calendar.setTime(date);
		calendar.add(Calendar.DATE, day); // 得到前几天
		Date yestedayDate = calendar.getTime();
		return yestedayDate;
	}

	/**
	 * 将字符串日期转换成java.util.Date类型
	 * <p>
	 * 日期时间格式yyyy-MM-dd
	 * 
	 * @param date
	 * @return
	 * @throws ParseException
	 */
	public static Date parseDate(String date) throws ParseException {
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
		return dateFormat.parse(date);
	}

	/**
	 * 为条件拼接上分库分表的库名后缀和表名后缀
	 * 
	 * @throws ParseException
	 */
	private List<String> getSearchCondition(QueryDataDto queryDataDto) throws ParseException {

		List<String> resList = new ArrayList<String>();
		Integer resourceType = queryDataDto.getResourceType();
		Date BeginTime = parseDate(queryDataDto.getBeginTime());
		Date EndTime = parseDate(queryDataDto.getEndTime());

		for (Date date = EndTime; date.after(getDateAlter(BeginTime, -1)); date = getDateAlter(date, -1)) {
			String databaseName = getDatabaseNameSuff(date, resourceType);
			String tableName = getTableName(resourceType, queryDataDto.getDataType());
			tableName += getTableNameSuff(date);

			String sql = getSearchSQL(queryDataDto, databaseName, tableName);
			if (StringUtils.isNotBlank(sql)) {
				resList.add(sql);
			}
		}
		return resList;
	}

	/**
	 * @Description: TODO 拼接库名后缀
	 * @param date
	 */
	private String getDatabaseNameSuff(Date date, Integer resourceType) {
		// 获取日志表名后缀
		String tableSuffix = new SimpleDateFormat("yyyyMMdd").format(date);
		// 获取库名后缀
		String databaseSuff = tableSuffix.substring(0, 6);
		String databaseName = PageConstant.LOG_DATABASE_NAME + databaseSuff;
		// if (resourceType == 118) {
		// databaseName = PageConstant.FPSOP_Log_STG + databaseSuff;
		// }
		return databaseName;
	}

	/**
	 * @Description: TODO 拼接表名后缀
	 * @param date
	 */
	private String getTableNameSuff(Date date) {
		// 获取日志表名后缀
		String tableSuffix = new SimpleDateFormat("yyyyMMdd").format(date);
		return tableSuffix;
	}

}
